<template>
	<view>
		<view class="uwo-nav-bar" :style="[{ height: customBar + 'px' }]">
			<view
				class="uwo-bar"
				:style="{
					height: customBar + 'px',
					backgroundColor: bgColor,
					color: textColor
				}"
			>
				<view class="uwo-status" :style="{ height: statusBarHeight + 'px' }"></view>
				<view
					class="uwo-nav"
					:style="{
						height: customBar - statusBarHeight + 'px'
					}"
				>
					<!-- <view class="left" @tap="handleBack">
						<template v-if="isBack">
							<text class="uwofont uwo-zuo"></text>
							<slot name="backText"></slot>
						</template>
					</view> -->
					<view class="content">
						<text class="uwofont uwo-zuo" @tap="handleBack" v-if="isBack"></text>
						<slot name="content"></slot>
					</view>
					<view class="right">
						<slot name="right"></slot>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
/**
 * 标题左侧，右侧可以有操作按钮
 */
import { computed, ref } from 'vue';
const statusBarHeight = ref(0);
const customBar = ref(0);
const props = defineProps({
	bgColor: {
		type: String,
		default: '#2979ff'
	},
	textColor: {
		type: String,
		default: '#FFFFFF'
	},
	isBack: {
		type: Boolean,
		default: true
	}
});

uni.getSystemInfo({
	success: function (e) {
		// #ifndef MP
		statusBarHeight.value = e.statusBarHeight;
		if (e.platform == 'android') {
			customBar.value = e.statusBarHeight + 50;
		} else {
			customBar.value = e.statusBarHeight + 45;
		}
		// #endif

		// #ifdef MP-WEIXIN
		statusBarHeight.value = e.statusBarHeight;
		let custom = wx.getMenuButtonBoundingClientRect();
		console.log(custom);
		customBar.value = custom.bottom + custom.top - e.statusBarHeight;
		// #endif

		// #ifdef MP-ALIPAY
		statusBarHeight.value = e.statusBarHeight;
		customBar.value = e.statusBarHeight + e.titleBarHeight;
		// #endif
	}
});
const handleBack = () => {
	if (props.isBack) {
		uni.navigateBack({
			delta: 1
		});
	}
};
</script>

<style scoped lang="scss">
.uwo-nav-bar {
	position: relative;

	.uwo-bar {
		position: fixed;
		width: 100%;
		top: 0;
		box-shadow: 0 1upx 6upx rgba(0, 0, 0, 0.1);
		min-height: 0px;
		box-shadow: 0upx 0upx 0upx;
		z-index: 9999;
		.uwo-status {
			height: 20px;
		}
		.uwo-nav {
			display: flex;
			align-items: center;
			justify-content: space-between;
			/* #ifdef MP-WEIXIN */
			padding-right: 220upx;
			/* #endif */
			/* #ifdef MP-ALIPAY */
			padding-right: 150upx;
			/* #endif */
			.content {
				padding-left: 10px;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				text-align: left;
				width: calc(100% - 200upx);
				font-size: 32upx;
				text-overflow: ellipsis;
				white-space: nowrap;
				overflow: hidden;
				.uwo-zuo {
					margin-right: 10px;
					font-size: 34upx;
				}
			}
			.right {
				width: 100upx;
				text-align: right;
				font-size: 30upx;
				padding-right: 30upx;
			}
		}
	}
}
</style>
